package com.yanqu.road.server.cmd.activity.zhenhuan;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ZhenHuanProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.zhenhuan.CrossZhenHuanMgr;
import com.yanqu.road.server.manager.activity.zhenhuan.CrossZhenHuanThirdProcessActivity;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C_CROSS_QUERY_ACTIVITY_USER_BASE_INFO, desc = "请求活动中的用户基本信息")
public class CrossQueryActivityUserBaseInfoCmd extends CrossCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        ZhenHuanProto.QueryActivityUserBaseInfoReqMsg reqMsg = ZhenHuanProto.QueryActivityUserBaseInfoReqMsg.parseFrom(packet.getBytes());

        ZhenHuanProto.QueryActivityUserBaseInfoRespMsg.Builder respMsg = ZhenHuanProto.QueryActivityUserBaseInfoRespMsg.newBuilder();
        respMsg.setRet(0);

        for (Long targetUserId : reqMsg.getUserIdsList()) {
            UserBaseInfo userBaseInfo = CrossUserMgr.getUserBaseInfo(targetUserId);
            if (userBaseInfo == null) {
                continue;
            }
            ZhenHuanProto.ActivityUserBaseInfoTemp.Builder temp = ZhenHuanProto.ActivityUserBaseInfoTemp.newBuilder();
            temp.setUserId(targetUserId);
            temp.setBaseInfo(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo));

            respMsg.addPlayerBaseData(temp);
        }
        MessageHelper.sendPacket(serverId, packet.getPlayerId(),
                YanQuMessageUtils.buildMessage(ClientProtocol.U_QUERY_ACTIVITY_USER_BASE_INFO, respMsg));
    }

    @Override
    public void sendData() {

    }
}
